﻿
// http://www.codeproject.com/Tips/191067/Sending-Email-Using-ASP-NET-using-Csharp-NET-With-.aspx


//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Web;
//using System.Web.UI;
//using System.Web.UI.WebControls;


using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;
using System.Web.Configuration;
using System.Configuration;

//namespace SendEmail

// http://www.codeproject.com/Tips/191067/Sending-Email-Using-ASP-NET-using-Csharp-NET-With-.aspx

//{
namespace Mercator2
{
//    public partial class EmailSender : System.Web.UI.Page
//    {
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SendGmail("gerson.freire@gmail.com", "gersonfaf61", "gerson.freire@gmail.com", 
                "gerson.freire@terra.com.br", "gerson.projetos@gmail.com", "teste", "teste", false);
        }
        
        protected void btnSendEmail_Click1(object sender, EventArgs e)
        {
			//System.Console.Beep(10000, 3000);
			MailMessage mail = new MailMessage();
			SmtpClient smtp = new SmtpClient()
			{
                Host = "smtp.gmail.com", //"smtp.collaborationhost.net", //smtp.gmail.com
				Port = 587,
				DeliveryMethod = SmtpDeliveryMethod.Network,
				UseDefaultCredentials = true,
				Credentials = new NetworkCredential(txtSender.Text.ToString(), txtPassword.Text.ToString())
			};
			MailAddress emailSender = new MailAddress(txtSender.Text, "BOOM");
			mail.From = emailSender;
			MailAddress receipient = new MailAddress(txtEmail.Text);
			mail.To.Add(receipient);
			mail.Body = txtArea.InnerText.ToString();
			mail.Subject = txtSubject.Text;
			smtp.Send(mail);

        }

        //http://www.velocityreviews.com/forums/t592366-send-mail-with-gmail.html
        public static void SendGmail(string userName, string password,
                string mailFrom,
                string mailTo, string commaDelimCCs, string
                subject, string message, bool isBodyHtml)
        {
            System.Net.Mail.MailMessage msg = new
            System.Net.Mail.MailMessage(mailFrom, mailTo,
            subject, message);
            msg.IsBodyHtml = isBodyHtml;
            if (commaDelimCCs != "")
                msg.CC.Add(commaDelimCCs);
            System.Net.NetworkCredential cred = new
            System.Net.NetworkCredential(userName, password);
            System.Net.Mail.SmtpClient mailClient = new
            System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
            mailClient.EnableSsl = true;
            mailClient.UseDefaultCredentials = false;
            mailClient.Credentials = cred;
            mailClient.Send(msg);
        }

    }
}